package com.xxx.controller;

import com.xxx.base.BaseController;
import com.xxx.common.model.BaseWrapper;
import com.xxx.common.constant.ParametersConstants;
import com.xxx.common.model.ReqUserId;
import com.xxx.interceptor.NeedAuth;
import com.xxx.model.user.req.ReqLoginVo;
import com.xxx.model.user.req.ReqUpdateUserInfoVO;
import com.xxx.model.user.res.ResLoginVo;
import com.xxx.service.user.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author Flying
 * @Description
 * @date 14:16 2018-08-24
 **/
@RestController
@Api(value = "用户接口", description = "用户接口")
public class UserController extends BaseController {


    @Autowired
    private UserService userService;

    @ApiOperation("登陆接口")
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public BaseWrapper<ResLoginVo> login(@Valid @ModelAttribute ReqLoginVo reqLoginVo){
        ResLoginVo result = userService.login(reqLoginVo);
        return new BaseWrapper<>(result);
    }

    /**
     * description:修改用户信息
     * @author: Flying
     * @date: 2018-08-28 12:31
     * @param: null
     * @return
     */
    @NeedAuth
    @RequestMapping(value = "/updateUserInfo", method = RequestMethod.POST,headers = {ParametersConstants.ACCESS_TOKEN})
    @ApiOperation("修改用户信息")
    public BaseWrapper<Integer> updateUserInfo(ReqUpdateUserInfoVO reqUpdateUserInfoVO){
        Integer result = userService.updateUserInfo(reqUpdateUserInfoVO);
        return new BaseWrapper<>(result);
    }

    /**
     * description:修改用户信息
     * @author: Flying
     * @date: 2018-08-28 12:31
     * @param: null
     * @return
     */
    @NeedAuth
    @RequestMapping(value = "/getUserInfo", method = RequestMethod.GET,headers = {ParametersConstants.ACCESS_TOKEN})
    @ApiOperation("获取用户信息")
    public BaseWrapper<ResLoginVo> getUserInfo(ReqUserId reqUserId){
        ResLoginVo result = userService.getUserInfo(reqUserId.getUserId());
        return new BaseWrapper<>(result);
    }





}
